package com.solidumgame.martillo.speed
{
	import com.pblabs.engine.PBE;
	import com.pblabs.engine.entity.EntityComponent;
	import com.solidumgame.martillo.score.events.ScoreGenericEvent;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import com.solidumgame.martillo.speed.event.SpeedGenericEvent;

	
	public class Speed extends EntityComponent
	{
		protected var speed:Number;
	
		public function Speed()
		{
			
		}
		
		override protected function onAdd():void{
			super.onAdd();
			owner.eventDispatcher.addEventListener(ScoreGenericEvent.SCORE_UPDATED_EVENT,updateSpeed);
		}
		
		override protected function onRemove():void{
			super.onRemove();
			owner.eventDispatcher.addEventListener(ScoreGenericEvent.SCORE_UPDATED_EVENT,updateSpeed);
		}
		
		protected function updateSpeed(e:ScoreGenericEvent):void{
			
			this.speed = e.score;
			
			PBE.mainStage.dispatchEvent(new SpeedGenericEvent(SpeedGenericEvent.SPEED_UPDATE_EVENT,speed));
			
		}
		
	}
}